package com.sumainfor.pc.market.service;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.dao.CommunityZfeignMapper;
import com.sumainfor.pc.market.feign.Zfeign.ZzuulFeign;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @Date 2018年11月7日
 * @Describe 工程部查询房源配置
 */
@Service
public class CommunityZfeignService implements Serializable {

    private ReentrantLock lock = new ReentrantLock(false);

    Logger log = LoggerFactory.getLogger(CommunityZfeignService.class);// 日志

    @Autowired
    private CommunityZfeignMapper communityZfeignMapper;
    @Autowired
    private ZzuulFeign zzuulFeign;
    /**
     * @return result
     * @Author Xfma
     * @Date 2018年11月7日
     * @Describe 查询所有的房源归属
     */
    public List<Map<String,Object>> getCommunityName(Map<String,Object> params) {
        List<Map<String,Object>> list=communityZfeignMapper.getCommunityName(params);
        return list;
    }
    /**
     * 根据房源编号 分页 模糊 条件查询房源信息
     *
     * @param params
     * @return
     */
    public List<Map<String,Object>> getCommunityList(Map<String,Object> params) {
        //查询房源的信息和服务管家 编号
        List<Map<String,Object>> marklist=communityZfeignMapper.getCommunityList(params);
        //保存客户报修人编号
        List<String> sysUserList=new ArrayList<String>();
        for (Map<String, Object> map : marklist) {
            if (map.get("SysUserId") != null) {
                //根据 HouId查询房源信息
                sysUserList.add(map.get("SysUserId").toString());
            }
        }
        if (sysUserList.size()>0){
            HashMap<String,Object> sysMap=new  HashMap<String,Object>();
            sysMap.put("sysUserList",sysUserList);
            JsonResult zuulResult=zzuulFeign.getReapirSysUser(sysMap);
            log.info("网关查询到的值:"+zuulResult);
            //根据归属管家的编号去查询管查询管家的信息
            List<Map<String,Object>> zuulList=(List<Map<String,Object>>)zuulResult.get("result");
            for (Map<String, Object> map : marklist) {
                for (Map<String, Object> map2 : zuulList) {
                    if (MapUtils.getString(map, "SysUserId").equals(MapUtils.getString(map2, "SysUserID"))) {
                        map.putAll(map2);
                    }
                }
            }
        }
        return marklist;
    }
    /**
     * 维修师傅根据获取项目编号列表
     */
    public List<Map<String,Object>> getComIdList(Map<String,Object> params){
        return communityZfeignMapper.getComIdList(params);
    }

    /**
     *  根据省市区街道楼号时候获取房源集合
     * @author zhoucong
     * @data 2019/9/10
     * @Param
     * @return
     */
    public List<Map<String,Object>> getHouInfoList(Map<String,Object> params){
        return communityZfeignMapper.getHouInfoList(params);
    }




    /**
     * 服务管家验房列表查询
     */
    public List<Map<String,Object>> getHouIdList(Map<String,Object> params){
        return communityZfeignMapper.getHouIdList(params);
    }
    /**
     *通过房源编号获取对应房源房源信息
     */
    public List<Map<String,Object>> getHouIdInfoList(Map<String,Object>params){
        return communityZfeignMapper.getHouIdInfoList(params);
    }
}
